package com.shqcjd.sinopecdemomobile.ui.adapter;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.shqcjd.sinopecdemomobile.R;
import com.shqcjd.sinopecdemomobile.model.pojo.ProblemDetailBean;
import com.shqcjd.sinopecdemomobile.model.pojo.UploadFileRet;
import com.shqcjd.sinopecdemomobile.ui.activity.preview.PreImageActivity;
import com.shqcjd.sinopecdemomobile.ui.activity.preview.VideosActivity;
import com.shqcjd.sinopecdemomobile.ui.activity.problem.ProblemMoreFileActivity;

import java.io.Serializable;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by sy on 2019/5/9.
 */

public class ProblemDetailAdapter extends BaseQuickAdapter<ProblemDetailBean.ExpertListBean,ProblemDetailAdapter.ViewHolder> {

    public ProblemDetailAdapter() {
        super(R.layout.item_problem_detail);
    }

    @Override
    protected void convert(ProblemDetailAdapter.ViewHolder helper, ProblemDetailBean.ExpertListBean item) {
//        RequestOptions options = new RequestOptions()
//                .placeholder(R.mipmap.ic_default_small)	//加载成功之前占位图
//                .error(R.mipmap.ic_default_small)	//加载错误之后的错误图
////                .override(88,87)	//指定图片的尺寸
//                .centerCrop();//指定图片的缩放类型为centerCrop （等比例缩放图片，直到图片的宽高都
//        Glide.with(mContext)
//                .load(item)
//                .apply(options)
//                .into(helper.iv_img);
        helper.tv_type.setText("专家答复("+item.expertUserName+")");
        helper.tv_info.setText("\u3000\u3000"+item.expertReply);
        helper.tv_time.setText(""+item.expertReplyTime);

        ProblemItemImgAdapter problemItemImgAdapter = new ProblemItemImgAdapter(item.expertReplyAttachments, mContext);
        helper.rv_video_img.setLayoutManager(new GridLayoutManager(mContext,3));
        helper.rv_video_img.setAdapter(problemItemImgAdapter);
        problemItemImgAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                UploadFileRet fileItem = (UploadFileRet) adapter.getItem(position);
                if(adapter.getData().size()>9&&position==8){
                    Intent intent = new Intent(mContext, ProblemMoreFileActivity.class);
                    Bundle bundle=new Bundle();
                    bundle.putSerializable("list",(Serializable)item.expertReplyAttachments);
                    intent.putExtras(bundle);
                    mContext.startActivity(intent);
                }else{
                    if(fileItem.extension.equals(".mp4")){
                        Intent it = new Intent(mContext, VideosActivity.class);
                        it.putExtra("url", fileItem.url);
                        it.putExtra("name", "视频详情");
                        mContext.startActivity(it);
                    }else{
                        Intent it = new Intent(mContext, PreImageActivity.class);
                        it.putExtra("url", fileItem.url);
                        it.putExtra("name", "图片详情");
                        mContext.startActivity(it);
                    }

                }
            }
        });


    }

    class ViewHolder extends BaseViewHolder {
        @BindView(R.id.tv_type)
        TextView tv_type;
        @BindView(R.id.tv_info)
        TextView tv_info;
        @BindView(R.id.rv_video_img)
        RecyclerView rv_video_img;
        @BindView(R.id.tv_time)
        TextView tv_time;
        public ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}